package org.deri.feather.common;



import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;

public class ConfigurationManager {
	
	private String configurationFile;
	
	private static ConfigurationManager uniqueInstance;
	
	final private String configFileName = "feather.config";
	
	private PropertiesConfiguration config;
	
	private ConfigurationManager(){
		
		configurationFile = configFileName;
	}
	
	public static synchronized ConfigurationManager getInstance(){
		if (uniqueInstance == null) {
			uniqueInstance = new ConfigurationManager();
		}
		return uniqueInstance;
	}
	
	public void setConfigurationFile(final String configurationFile){
		this.configurationFile = configurationFile;
	}
	
	public String getValue(String parameter){

		try {
			this.config = new PropertiesConfiguration(configurationFile);
		} catch (ConfigurationException e) {
			e.printStackTrace();
		}
	    return config.getString(parameter);
		
	}
	
	public boolean enableKeywordIndex() {
		String value = getValue("enable_keyword_index");
		
		if (!(value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")))
			System.out.println("The value for enable_keyword_index is not valid. Changing it to 'false'..");
		
		if (value.equalsIgnoreCase("true")) {
			return true;
		} 
			
		return false;
	}
	
	public boolean enableLiteralIndex() {
		String value = getValue("enable_literal_index");
		
		if (!(value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")))
			System.out.println("The value for enable_literal_index is not valid. Changing it to 'false'..");
		
		if (value.equalsIgnoreCase("true")) {
			return true;
		} 
			
		return false;
	}
	
}
	
